package cn.josh.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;



public class EncodingFilter implements Filter 
{

	//销毁时
	public void destroy() 
	{
		System.out.println("EncodingFilter:" + "销毁了");
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException 
	{
		//处理中文乱码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		
		//放行的操作
		chain.doFilter(request, response);
		
	}

	//创建时
	public void init(FilterConfig arg0) throws ServletException
	{
		System.out.println("EncodingFilter:" + "创建了");
		
	}


}
